﻿using LanguagePolish.Controls.Meta;
using LanguagePolish.EntityModel;
using LanguagePolish.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace LanguagePolish.Views
{
    /// <summary>
    /// Interaction logic for ClassInfoView.xaml
    /// </summary>
    public partial class ClassInfoView : Window
    {
        public ClassInfoView()
        {
            InitializeComponent();
        }

        public ClassInfoView(Class myClass)
        {
            InitializeComponent();
            calendar.LessonsProvider = new ClassLessonsProvider(myClass);
            calendar.EnableMenu = false;
            ClassInfoViewModel vm = new ClassInfoViewModel(myClass);
            DataContext = vm;
        }

        private void GradeGrid_OnAutoGeneratingColumn(object sender, DataGridAutoGeneratingColumnEventArgs e)
        {
            if (e.Column.Header.ToString() == "Lesson")
            {
                e.Column.Visibility = Visibility.Collapsed;
                return;
            }
            if (e.Column.Header.ToString().EndsWith("_GRADE"))
            {
                e.Column.Visibility = Visibility.Collapsed;
                return;
            }
            // Data-column
            if (e.PropertyType == typeof (DateTime))
            {
                (e.Column as DataGridTextColumn).Binding.StringFormat = "MMM dd";
                e.Column.IsReadOnly = true;
                e.Column.Width = new DataGridLength(50, DataGridLengthUnitType.Pixel);
            }
            else
            {
                e.Column.Width = new DataGridLength(1, DataGridLengthUnitType.Star);
            }
        }
    }
}
